﻿#region
/*******************************************************************************
** File Name:		    FoodCategoryService.cs
** Creator:		        chao.jiang 
** EMail:               chao.jiang 
** Create date:	        
** Latest Modifier:
** Latest Modify date:
** Description:		    
** Modify History:
**
** Code Review:
**
** Version number:       1.0.0
*********************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using EWineShop.Service.Contracts;
using EWineShop.Service.Model;
using EWineShop.IBatisRepository;
using EWineShop.Respository;
using System.Data;
using EWineShop.Entity;

namespace EWineShop.Service
{
    public class FoodCategoryService : IFoodCategoryService
    {
		 IFoodCategory foodCategory = new FoodCategoryRepository();
		 
		 #region  Auto Generation
		 
        public void AddFoodCategory(FoodCategoryModel model)
        {
			EFoodCategory entity = ConvertModelToEntity(model);
			
            foodCategory.AddFoodCategory(entity);
        }

		public void UpdateByFoodCategoryID (FoodCategoryModel model)
		{
			EFoodCategory entity = ConvertModelToEntity(model);

            foodCategory.UpdateByFoodCategoryID(entity);

		}

		public void DeleteByFoodCategoryID (System.Int64 foodCategoryID)
		{
		
            foodCategory.DeleteByFoodCategoryID(foodCategoryID);

		}
		 
        public FoodCategoryModel GetByFoodCategoryID (System.Int64 foodCategoryID)
        {
        
			EFoodCategory entity = foodCategory.GetByFoodCategoryID(foodCategoryID);
			
            FoodCategoryModel model = ConvertEntityToModel(entity);


            return model;
        }
        
	
		public IList<FoodCategoryModel> GetAll ()
		{
			IList<EFoodCategory> entity = foodCategory.GetAll();

            if (entity == null)
            {
                return null;
            }
            
            IList<FoodCategoryModel> list = new List<FoodCategoryModel>();

            foreach (var item in entity)
            {
                FoodCategoryModel model = ConvertEntityToModel(item);
                list.Add(model);
            }
            return list;   
			
		}
		
		public FoodCategoryModel ConvertEntityToModel(EFoodCategory entity)
		{
			if (entity == null)
            {
                return null;
            }
			FoodCategoryModel model = new FoodCategoryModel();
                        model.FoodCategoryID = entity.FoodCategoryID;
                        model.Name = entity.Name;
                        model.Remark = entity.Remark;
                        model.CreateTime = entity.CreateTime;
                        model.UpdateTime = entity.UpdateTime;
                        return model;
		}
		
		public EFoodCategory ConvertModelToEntity(FoodCategoryModel model)
		{
			if (model == null)
            {
                return null;
            }
			EFoodCategory entity = new EFoodCategory();
                        entity.FoodCategoryID = model.FoodCategoryID;
                        entity.Name = model.Name;
                        entity.Remark = model.Remark;
                        entity.CreateTime = model.CreateTime;
                        entity.UpdateTime = model.UpdateTime;
                        return entity;
		}
		
		
		
		#endregion
    }
}